﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ApartmanYonetim.Formlar
{
    public partial class UyeDuzenle : Form
    {
        public UyeDuzenle()
        {
            InitializeComponent();
        }

        public string id { get; set; }

        Siniflar.Veritabani vt = new Siniflar.Veritabani();
        Siniflar.Fonksiyon fn = new Siniflar.Fonksiyon();

        private void UyeDuzenle_Load(object sender, EventArgs e)
        {
            fn.ComboboxDoldur("SELECT * FROM AidatGrubu", "ID", "Adi", cmbAidatGrubu);
            fn.ComboboxDoldur("SELECT * FROM Bloklar", "ID", "Adi", cmbBlok);
            cmbOturan.DataSource = Enum.GetValues(typeof(Siniflar.Oturan));

            DataRow dr = vt.GetDataRow("SELECT * FROM dbo.Uyeler AS U JOIN dbo.Bloklar AS B ON B.ID=U.BlokID JOIN dbo.AidatGrubu AS AG ON AG.ID=U.AidatGrubuID WHERE U.ID='"+id+"'");
            txtAdiSoyadi.Text = dr["AdiSoyadi"].ToString();
            txtTCKN.Text = dr["TCKN"].ToString();
            txtCepTel.Text = dr["CepTelefonu"].ToString();
            txtDigerTel.Text = dr["DigerTelefon"].ToString();
            txtEposta.Text = dr["EpostaAdresi"].ToString();
            dtpDogumTarih.Value = Convert.ToDateTime(dr["DogumTarihi"]);
            txtCalistiğiKurum.Text = dr["CalistigiKurum"].ToString();
            txtAdres.Text = dr["IkinciAdres"].ToString();
            txtAciklama.Text = dr["Aciklama"].ToString();
            cmbBlok.Text = dr["Adi"].ToString();
            cmbDaireNo.Text = dr["DaireNo"].ToString();
            cmbAidatGrubu.Text = dr["Adi1"].ToString();
            cmbOturan.Text = ((Siniflar.Oturan)(Convert.ToInt32(dr["OturanID"]))).ToString();
        }

        private void cmbBlok_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ID", typeof(int));
            dt.Columns.Add("text", typeof(string));
            cmbDaireNo.ValueMember = "ID";
            cmbDaireNo.DisplayMember = "text";


            string a = cmbBlok.SelectedValue.ToString();

            if (a == "0")
            {

                cmbDaireNo.DataSource = dt;
                cmbDaireNo.Text = "";
                cmbDaireNo.Enabled = false;
            }
            else
            {
                cmbDaireNo.Enabled = true;
                int DaireSayisi = int.Parse(vt.GetDataCell("SELECT DaireSayisi FROM Bloklar WHERE ID='" + a + "'"));

                for (int i = 1; i <= DaireSayisi; i++)
                {
                    if (i < 10)
                    {
                        dt.Rows.Add(i, "0" + i.ToString());
                    }
                    else
                    {
                        dt.Rows.Add(i, i.ToString());
                    }
                }

                cmbDaireNo.DataSource = dt;
            }
        }
    }
}
